var opinionPrice;

/**
 * 设置结果接收对象
 * @param _opinionPrice
 */
function setModel(_opinionPrice) {
    if (_opinionPrice == undefined || !(_opinionPrice instanceof com.jf.crawl.model.OpinionPrice)) {
        throw new java.lang.Exception("opinionPrice 对象为空");
    }
    log.info("opinionPrice {}", _opinionPrice)
    opinionPrice = _opinionPrice;
}

function crawler() {
    var html = Get("https://box.jimu.com/Project/List");
    var doc = Jsoup.parse(html);
    var items = doc.select(".invest-item");
    for (var i = 0; i < items.size(); i++) {
        var item = items.get(i);
        var day = item.select(".subtitle").text().substr(4, 2);
        if (day == getToday()) {
            var eles = item.select(".invest-item-profit");
            if (eles.size() > 1) {
                var price = eles.get(0).text().trim().replace("%", "");
                var month = eles.get(1).text();
                if ("1" == month) {
                    opinionPrice.setOneMonth(commonUtil.string2Decimal(price));
                } else if ("2" == month) {
                    opinionPrice.setTwoMonth(commonUtil.string2Decimal(price));
                } else if ("3" == month) {
                    opinionPrice.setThreeMonth(commonUtil.string2Decimal(price));
                } else if ("6" == month) {
                    opinionPrice.setSixMonth(commonUtil.string2Decimal(price));
                } else if ("12" == month) {
                    opinionPrice.setOneYear(commonUtil.string2Decimal(price));
                } else if ("24" == month) {
                    opinionPrice.setTwoYear(commonUtil.string2Decimal(price));
                } else if ("36" == month) {
                    opinionPrice.setThreeYear(commonUtil.string2Decimal(price));
                }
            }
        }
        else {
            log.info("非当天产品,{}", day);
        }
    }
    return true;
}

function getToday() {
    var date = new Date();
    var day = date.getDate();
    return day;
}